<?php

/*
 * Project: oCoder Framework
 * File: /controllers/home.php
 * Purpose: controller for the home of the app.
 * Author: Trung Hoang
 */

class HomeController extends BaseController {

    //add to the parent constructor
    public function __construct($action, $urlValues) {
        parent::__construct($action, $urlValues);

        //create the model object
        require ("models/home.php");
        $this->model = new HomeModel();
    }

    //default action
    protected function index() {
        $this->view->output($this->model->home(), 'home');
    }

    public function getListDate() {
        if (isset($_POST)) {
            $return = $this->model->getList($_POST['class_id'], $_POST['fromDate'], $_POST['toDate']);
            header('Content-type: application/json');
            if ($return->lstSchedule == null) {
                $arr = array();
            } else {
                $arr = $return->lstSchedule;
            }
            echo json_encode($arr);
            exit();
        }
    }

    //admin action
    protected function admin() {
        $this->view->output($this->model->index());
    }

    protected function viewDetail() {
        $id = $this->urlValues['id'];
        if (!empty($id)) {
            $this->view->output($this->model->viewDetail($id), 'home');
        } else {
            header("Location: " . BASE_URL . "Error/badURL");
        }
    }

    protected function viewsContent() {
        $id = $this->urlValues['id'];
        if (!empty($id)) {

            $page = max(1, intval($this->urlValues['page']));
            $this->view->output($this->model->viewsContent($id, $page), 'home');
        } else {
            header("Location: " . BASE_URL . "Error/badURL");
        }
    }

    protected function timetable() {
        $id = $this->urlValues['id']; //tr? v? s? tu?n c?n xem th?i kh�a bi?u
        $this->view->output($this->model->timetable($id), 'home');
    }

    protected function viewsSchedule() {
        $id = $this->urlValues['id'];
        $page = max(1, intval($this->urlValues['page']));
        $this->view->output($this->model->viewsSchedule($id, $page), 'home');
    }

    protected function AboutUs() {
        $this->view->output($this->model->AboutUs(), 'home');
    }

    protected function Contact() {
        $this->view->output($this->model->Contact(), 'home');
    }

}
?>


